package com.zerdoor.filter;

/**
 * Created by xiaobo on 2014/9/1.
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestFilter implements Filter {

    // 创建线程
    public static ThreadLocal<HttpServletRequest> threadLocal = new ThreadLocal<HttpServletRequest>();

    public static final String SESSION_DATE = "appliedDate";

    public void destroy() {
        // TODO Auto-generated method stub

    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        threadLocal.set((HttpServletRequest) arg0);
        //HttpServletRequest request = ((HttpServletRequest) arg0);
        HttpServletResponse response = ((HttpServletResponse) arg1);
        response.addHeader("Cache-Control", "no-cache");
        response.addHeader("Pragma", "No-cache");
        response.addDateHeader("Expires", 0);
        arg2.doFilter(arg0, arg1);
    }

    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub

    }

}

